allCityList = ['济南市', '青岛市', '淄博市', '枣庄市', '东营市', '烟台市', '潍坊市',
    '济宁市', '泰安市', '威海市', '日照市', '莱芜市', '临沂市', '德州市', '聊城市', '滨州市', '菏泽市']


//echart1 & mapechart
cityList1 = Array();
countList1 = Array();
mapRawData1 = Array();


// $.ajax({
//     url: '/getOltNeedExpand',
//     dataType: 'JSON',
//     async: false,
//     success: function (data) {
//         for (i in data) {
//             cityList1.push(data[i]['city'].substr(0, 1)+" "+data[i]['city'].substr(1, 1));
//             countList1.push(data[i]['countOlt']);
//             var tempArray = [];
//             tempArray.push(data[i]['city'].substr(0, 2))
//             tempArray.push(data[i]['countOlt'])
//             mapRawData1.push(tempArray)
//         }
//
//     }
// });
valList = countList1;


cityList2 = Array();
countList2 = Array();
mapRawData2 = Array();


cityList3 = Array();
countOLTList3 = Array();
countSWList3 = Array();
mapRawData3 = Array();
sumList3 = Array()
$.ajax({
    url: '/getAllNeedExpand',
    dataType: 'JSON',
    async: false,
    success: function (data) {
        for (i in data) {
            cityList3.push(data[i]['city'].substr(0, 1) + "\n" + data[i]['city'].substr(1, 1));
            countOLTList3.push(data[i]['countOlt']);
            countSWList3.push(data[i]['countSW']);
            var tempArray = [];
            tempArray.push(data[i]['city'].substr(0, 2));
            tempArray.push(data[i]['countOlt']);
            tempArray.push(data[i]['countSW']);
            mapRawData1.push(tempArray);
            sumList3.push(data[i]['countOlt'] + data[i]['countSW']);
        }
    }
});
valList = sumList3;

function getCityDetail(city_name) {

    $('#city_name')[0].innerText=city_name.substr(0,2);
    $.ajax({
        url: '/getCityDetail?city_name=' + city_name,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            // console.log($('#all_user_span'))
            $('#all_user_span')[0].innerText = data['all_user'];
            $('#all_act_user_span')[0].innerText = data['all_act_user'];
            $('#all_itv_span')[0].innerText = data['all_itv'];
            $('#all_sw_span')[0].innerText = data['all_sw'];
            $('#all_olt_span')[0].innerText = data['all_olt'];
        }
    });

    $.ajax({
        url: '/getSWNeedExpandNumByCity?city_name=' + city_name,
        dataType: 'JSON',
        async: false,
        success: function (data) {
           drawBarSW(data[0]['countSW'],'sw_95');
            drawBarSW(data[1]['countSW'],'sw_90');
            drawBarSW(data[2]['countSW'],'sw_80');
            drawBarSW(data[3]['countSW'],'sw_70');
            drawBarSW(data[4]['countSW'],'sw_60');
            drawBarSW(data[5]['countSW'],'sw_etc');
        }
    });

    $.ajax({
        url: '/getOLTNeedExpandNumByCity?city_name=' + city_name,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            drawBarOLT(data[0]['countOLT'],'olt_95');
            drawBarOLT(data[1]['countOLT'],'olt_90');
            drawBarOLT(data[2]['countOLT'],'olt_80');
            drawBarOLT(data[3]['countOLT'],'olt_70');
            drawBarOLT(data[4]['countOLT'],'olt_60');
            drawBarOLT(data[5]['countOLT'],'olt_etc');
        }
    });
    boundList = Array();
    $.ajax({
        url: '/getCityBoundList?city_name=' + city_name,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            cityBoundData = data;
            console.log(cityBoundData)
            for(var i=0;i<data.length;i++){
                boundList.push(data[i]['name'])
            }
        }
    });
    optionCityBound = {
        title : {
            text: '宽带用户带宽分布',
            x:'left',
            textStyle:{
                color: '#FFFFFF',
                fontSize: 30
            }
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            x: 'right',
            data:boundList,
            textStyle:{
                fontSize: 15,
                color: '#FFFFFF'
            }
        },
        grid:{
          top: 0,
          bottom: 0
        },
        series: [
            {
                name:'宽带用户带宽分布',
                type:'pie',
                radius: ['50%', '70%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '30',
                            fontWeight: 'bold'
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data:cityBoundData
            }
        ]
    };
}


// $.ajax({
//     url: '/getSWNeedExpand',
//     dataType: 'JSON',
//     async: false,
//     success: function (data) {
//         for (i in data) {
//             cityList2.push(data[i]['city'].substr(0, 1)+" "+data[i]['city'].substr(1, 1));
//             countList2.push(data[i]['countSW']);
//             var tempArray = [];
//             tempArray.push(data[i]['city'].substr(0, 2))
//             tempArray.push(data[i]['countSW'])
//             mapRawData2.push(tempArray)
//         }
//
//     }
// });


// $.ajax({
//     url: '/getEponPortExpand',
//     dataType: 'JSON',
//     async: false,
//     success: function (data) {
//         for (i in data) {
//             cityList4.push(data[i]['city'].substr(0, 1)+" "+data[i]['city'].substr(1, 1));
//             countListE4.push(data[i]['countEpon']);
//             var tempArray = [];
//             tempArray.push(data[i]['city'].substr(0, 2))
//             tempArray.push(data[i]['countEpon'])
//             mapRawDataE4.push(tempArray)
//         }
//     }
// });
//
// $.ajax({
//     url: '/getGponPortExpand',
//     dataType: 'JSON',
//     async: false,
//     success: function (data) {
//         for (i in data) {
//             countListG4.push(data[i]['countGpon']);
//             var tempArray = [];
//             tempArray.push(data[i]['city'].substr(0, 2))
//             tempArray.push(data[i]['countGpon'])
//             mapRawDataG4.push(tempArray)
//         }
//
//     }
// });
//
// xList2 = Array();
// mapRawDataN2 = Array();
// mapRawDataY2 = Array();
// qualityListN2 = Array();
// qualityListY2 = Array();

// $.ajax({
//     url: '/getNotDirectOLTITVQuality',
//     dataType: 'JSON',
//     async: false,
//     success: function (data) {
//         for (i in data) {
//             xList2.push(data[i]['seq']);
//             qualityListN2.push(parseFloat(data[i]['itv_delay']));
//
//             var tempArray = [];
//             tempArray.push(data[i]['seq'])
//             tempArray.push(parseFloat(data[i]['itv_delay']))
//             mapRawDataN2.push(tempArray)
//         }
//     }
// });

// $.ajax({
//     url: '/getDirectOLTITVQuality',
//     dataType: 'JSON',
//     async: false,
//     success: function (data) {
//         for (i in data) {
//             qualityListY2.push(parseFloat(data[i]['itv_delay']));
//
//             var tempArray = [];
//             tempArray.push(data[i]['seq'])
//             tempArray.push(parseFloat(data[i]['itv_delay']))
//             mapRawDataY2.push(tempArray)
//         }
//
//     }
// });


$.ajax({
    url: '/getAllDisplayInfo',
    dataType: 'JSON',
    async: false,
    success: function (data) {
        console.log(data)
        allUserDiv = document.getElementById('all_user_div');
        newData = formatInt(data['all_user']).toString()
        var dataLength = newData.toString().length;
        for (i = 0; i < dataLength; i++) {
            if (newData[i] == ',') {
                allUserDiv.innerHTML += '<span style="color: #00E0FF;font-size: 48px;">,</span>';
            } else {
                allUserDiv.innerHTML += '<span class="all_user_num_span">' + newData[i] + '</span>';
            }
        }


        allActUserDiv = document.getElementById('all_act_user_div');
        newData = formatInt(data['all_act_user']).toString()
        dataLength = newData.toString().length;

        for (i = 0; i < dataLength; i++) {
            if (newData[i] == ',') {
                allActUserDiv.innerHTML += '<span style="color: #EA4D58;font-size: 48px;">,</span>';
            } else {
                allActUserDiv.innerHTML += '<span class="all_act_user_num_span">' + newData[i] + '</span>';
            }
        }

        allActItvDiv = document.getElementById('all_itv_div');
        newData = formatInt(data['all_ITV']).toString()
        dataLength = newData.toString().length;

        for (i = 0; i < dataLength; i++) {
            if (newData[i] == ',') {
                allActItvDiv.innerHTML += '<span style="color: #F1E723;font-size: 48px;">,</span>';
            } else {
                allActItvDiv.innerHTML += '<span class="all_act_itv_num_span">' + newData[i] + '</span>';
            }
        }
        swCountSpan = document.getElementById('sw_count_span');
        swCountSpan.innerText=data['all_sw'];
        oltCountSpan = document.getElementById('olt_count_span');
        oltCountSpan.innerText=data['all_olt'];


    }
});


function getPonUserList(oltName) {
    var data_info = '[';
    $.ajax({
        url: '/getOltPonUserCount?olt_name='+oltName,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            // console.log(data);
            var if_board = data[0]['if_position'].split('-')[2];
            data_info += "{ " +
                "name: '"+if_board+"', " +
                // "    itemStyle: { " +
                // "        color: '#da0d68' " +
                // "    }, " +
                "children:[";

            for(var i=0;i<data.length;i++){
                var if_info = data[i]['if_position'].split('-');
                // console.log(if_info);
                if(if_info[2] != if_board){
                    if_board = if_info[2];
                    data_info = data_info.substr(0,data_info.length-1) + "]},{ " +
                        "name: '"+if_info[2]+"', " +
                        // "    itemStyle: { " +
                        // "        color: '#da0d68' " +
                        // "    }, " +
                        "children:[";
                }
                data_info += "{ " +
                    "name: '"+if_info[2]+"-"+if_info[3]+"', " +
                    "value: 1, " +
                    "itemStyle: { " +
                    // "            color: '#975e6d' " +
                    "},children:[{ " +
                    "name:'"+data[i]['userCount']+"', " +
                    "value: 1 " +
                    "}] " +
                    "},";
            }
            data_info = data_info.substr(0,data_info.length-1) + ']}]'
        }
    });
    // console.log(data_info)

    return data_info;

}


function getOltListCalculateOnBroadbandByCity(city_name) {
    calculate_olt_line_list = Array();
    olt_old_line_flow = Array();
    olt_new_line_flow = Array();
    $.ajax({
        url: '/getOltListCalculateOnBroadbandByCity?city_name=' + city_name,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data);
            for(var i =0;i<data.length;i++){
                calculate_olt_line_list.push(data[i]['olt_name']);
                olt_old_line_flow.push(data[i]['p_in_olt']);
                olt_new_line_flow.push(data[i]['p_new_in_olt_line']);
            }
        }
    })
    console.log(olt_old_line_flow)
    console.log(olt_new_line_flow)
    console.log(calculate_olt_line_list)
}

function getSWListCalculateOnBroadbandByCity(city_name) {
    calculate_sw_line_list = Array();
    sw_old_line_flow = Array();
    sw_new_line_flow = Array();
    $.ajax({
        url: '/getSWListCalculateOnBroadbandByCity?city_name=' + city_name,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data);
            for(var i =0;i<data.length;i++){
                calculate_sw_line_list.push(data[i]['A_name']);
                sw_old_line_flow.push(data[i]['p_in_sw']);
                sw_new_line_flow.push(data[i]['p_new_in_sw_line']);
            }
        }
    })
}


function getOLTListCalculateOnITVByCity(city_name) {
    calculate_olt_itv_list = Array();
    olt_old_itv_flow = Array();
    olt_new_itv_flow = Array();
    $.ajax({
        url: '/getOLTListCalculateOnITVByCity?city_name=' + city_name,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data);
            for(var i =0;i<data.length;i++){
                calculate_olt_itv_list.push(data[i]['olt_name']);
                olt_old_itv_flow.push(data[i]['p_in_olt']);
                olt_new_itv_flow.push(data[i]['p_new_in_olt']);
            }
        }
    })
}

function getSWListCalculateOnITVByCity(city_name) {
    calculate_sw_itv_list = Array();
    sw_old_itv_flow = Array();
    sw_new_itv_flow = Array();
    $.ajax({
        url: '/getSWListCalculateOnITVByCity?city_name=' + city_name,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data);
            for(var i =0;i<data.length;i++){
                calculate_sw_itv_list.push(data[i]['A_name']);
                sw_old_itv_flow.push(data[i]['p_in_sw']);
                sw_new_itv_flow.push(data[i]['p_new_in_sw']);
            }
        }
    })
}
